using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace XFGameFramework.PanelExtension
{ 
    [CustomEditor(typeof(SelectableNavigation))]
    public class SelectableNavigationInspector : Editor
    {

        private SerializedProperty mScript = null;
        private SerializedProperty defaultSelected = null;

        private SerializedProperty upType = null;
        private SerializedProperty upSelectables = null;

        private SerializedProperty downType = null;
        private SerializedProperty downSelectables = null;

        private SerializedProperty leftType = null;
        private SerializedProperty leftSelectables = null;

        private SerializedProperty rightType = null;
        private SerializedProperty rightSelectables = null;

        private bool foldoutUp = true;

        private bool foldoutDown = true;

        private bool foldoutLeft = true;

        private bool foldoutRight = true;

        private void OnEnable()
        {
            mScript = serializedObject.FindProperty("m_Script");
            defaultSelected = serializedObject.FindProperty("defaultSelected");

            SerializedProperty up = serializedObject.FindProperty("up");
            upType = up.FindPropertyRelative("Type");
            upSelectables = up.FindPropertyRelative("selectables");

            SerializedProperty down = serializedObject.FindProperty("down");
            downType = down.FindPropertyRelative("Type");
            downSelectables = down.FindPropertyRelative("selectables");

            SerializedProperty left = serializedObject.FindProperty("left");
            leftType = left.FindPropertyRelative("Type");
            leftSelectables = left.FindPropertyRelative("selectables");

            SerializedProperty right = serializedObject.FindProperty("right");
            rightType = right.FindPropertyRelative("Type");
            rightSelectables = right.FindPropertyRelative("selectables");

        }


        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.PropertyField(mScript);
            EditorGUI.EndDisabledGroup();

            EditorGUILayout.PropertyField(defaultSelected);

            foldoutUp = EditorGUILayout.Foldout(foldoutUp, "Up");

            if (foldoutUp)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(20);
                EditorGUILayout.BeginVertical();

                EditorGUILayout.PropertyField(upType);
                if (upType.enumValueIndex == 1)
                    EditorGUILayout.PropertyField(upSelectables);

                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
            }

            foldoutDown = EditorGUILayout.Foldout(foldoutDown, "Down");

            if (foldoutDown)
            {

                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(20);
                EditorGUILayout.BeginVertical();

                EditorGUILayout.PropertyField(downType);
                if (downType.enumValueIndex == 1)
                    EditorGUILayout.PropertyField(downSelectables);

                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
            }

            foldoutLeft = EditorGUILayout.Foldout(foldoutLeft, "Left");

            if (foldoutLeft)
            {

                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(20);
                EditorGUILayout.BeginVertical();

                EditorGUILayout.PropertyField(leftType);
                if (leftType.enumValueIndex == 1)
                    EditorGUILayout.PropertyField(leftSelectables);

                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();


            }

            foldoutRight = EditorGUILayout.Foldout(foldoutRight, "Right");

            if (foldoutRight)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(20);
                EditorGUILayout.BeginVertical();

                EditorGUILayout.PropertyField(rightType);
                if (rightType.enumValueIndex == 1)
                    EditorGUILayout.PropertyField(rightSelectables);

                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
            }


            serializedObject.ApplyModifiedProperties();

        }


    }
}